Perl@Work#1 - RESTful URLs, the path info, and code paths

Ron Savage on 2009-10-09T04:43:53

Hi Folks

Well, no word from Perlsphere, so here's the first in the series:

Perl@Work#1: http://savage.net.au/Perl-at-work/html/restful.urls.html

I've written 420 lines (incl blanks) on the second article, but there's a way to go yet...


barely RESTful

daxim on 2009-10-09T10:11:36

Samples:

  • /person/add

    Use class CGI::Office::Contacts::Controller::Person, and call method add.

  • /organization_notes/delete/99

    Use class CGI::Office::Contacts::Controller::Organization::Notes, and call method delete, with an object id of 99.

This is service trampled REST, very much still in the vein of old web services.

Also, you haven't written about HTTP methods at all, which are the central piece. URLs denote things, therefore are just nouns, and the resources themselves are well-defined well-adopted types to aid interoperability. The verbs go in front and have standard semantics for the Web.

To delete, use DELETE.

DELETE /organization_notes/99 HTTP/1.1
---
HTTP/1.1 410 Gone

To create, use PUT.

PUT /person/123 HTTP/1.1
Content-Type: text/x-vcard

BEGIN:VCARD...
---
HTTP/1.1 201 Created
Location: /person/123

But realistically, in most architectures you cannot know the id before you have made the request. The workaround is to POST to a collection, see AtomPub.

Re:barely RESTful

Ron Savage on 2009-10-09T23:53:50

Hi daxim

Well, I didn't claim to know everything :-).

And what does 'trampled' mean in this context?

Cheers

Re:barely RESTful

daxim on 2009-10-12T09:51:46

'lo Ron, let me google that for you.

http://duncan-cragg.org/blog/post/strest-service-trampled-rest-will-break-web-20 /

I see you put a disclaimer on the article. Won't discuss HTTP methods? — I hope those delete actions and other state changes are only available through POST.